import { makeAutoObservable, runInAction } from "mobx";
import http from '@/request'
import { categoryType } from "@/types";
import account from "./account";


class Store {
    categoryList: categoryType[]
    categoryMap: {}
    doUpDateCategorys = () => {
        http.get('/category/list', {
            accountId: account.activeAccount?.id
        }).then(res => {
            runInAction(() => {
                this.categoryList = res.data || [] as categoryType[]
                this.categoryMap = this.categoryList.reduce((obj, cur) => {
                    return cur.id ? {
                        ...obj,
                        [cur.id]: cur
                    } : obj
                }, {})
            })
        }).catch(err => {
            console.log(err)
        })
    }
  constructor() {
    makeAutoObservable(this);
  }
}

export default new Store();
